package com.itheima.web;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class ReportController1 {
    @RequestMapping("/exportExcel")
    public void reportExcel() throws Exception{
        TemplateExportParams params = new TemplateExportParams("report_template.xlsx");

        Map data = new HashMap<>();
        data.put("curdate","10.29");
        data.put("curdatemember","2");
        data.put("totalmemebers","10");
        data.put("curweekmember","3");
        data.put("curmonthmemebers","4");
        data.put("curordersettings","1");
        data.put("curorderedsettings","1");
        data.put("curweekordersettings","3");
        data.put("curweekorderedsettings","2");
        data.put("curmonthordersettings","5");
        data.put("curmonthorderedsettings","3");

        List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();

        Map<String, String> lm = new HashMap<String, String>();
        for (int i = 0; i < 4; i++) {
            lm.put("name", "粉红珍爱(女)升级TM12项筛查体检套餐");
            lm.put("counts", "5");
            lm.put("zhanbi", "0.378");
            lm.put("remark", "");

            listMap.add(lm);
        }
        data.put("list", listMap);

        /*List<Map<String, String>> listMap2 = new ArrayList<Map<String, String>>();

        Map<String, String> lm2 = new HashMap<String, String>();
        for (int i = 0; i < 1; i++) {
            lm2.put("name", "阳光爸妈升级肿瘤12项筛查体检套餐");
            lm2.put("counts", "3");
            lm2.put("zhanbi", "0.285");
            lm2.put("remark", "");

            listMap1.add(lm2);
        }

        data.put("list", listMap2);*/

        Workbook workbook = ExcelExportUtil.exportExcel(params,data);
        OutputStream os = new FileOutputStream("D:/exportData.xlsx");
        workbook.write(os);
        os.flush();
        os.close();

    }
}
